package com.jiuzhou.guanwang.jzcp.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.base.BaseFragment;

public class SportFragment extends BaseFragment implements View.OnClickListener {
    private GroupFragment mJclqFragment;
    private ScheduleFragment mJczqFragment;
    private RelativeLayout mLqRl;
    private TextView mLqTv;
    private View mLqV;
    private RelativeLayout mZqRl;
    private TextView mZqTv;
    private TextView title;
    private View mZqV;

    protected void initView(View view) {
        title = view.findViewById(R.id.title);
        title.setText("实时比分");
        this.mZqRl = (RelativeLayout) view.findViewById(R.id.rl_zq);
        this.mLqRl = (RelativeLayout) view.findViewById(R.id.rl_lq);
        this.mZqTv = (TextView) view.findViewById(R.id.tv_zq);
        this.mLqTv = (TextView) view.findViewById(R.id.tv_lq);
        this.mZqV = view.findViewById(R.id.view_zq);
        this.mLqV = view.findViewById(R.id.view_lq);
        this.mZqRl.setOnClickListener(this);
        this.mLqRl.setOnClickListener(this);
    }

    public static SportFragment newInstance(String info) {
        Bundle args = new Bundle();
        SportFragment fragment = new SportFragment();
        args.putString("info", info);
        fragment.setArguments(args);
        return fragment;
    }


    protected int bindLayout() {
        return R.layout.activity_world_cup;
    }

    protected void initData() {
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        if (this.mJczqFragment == null) {
            this.mJczqFragment = new ScheduleFragment();
        }
        if (this.mJclqFragment == null) {
            this.mJclqFragment = new GroupFragment();
        }

        transaction.add((int) R.id.view_container, this.mJczqFragment);
        transaction.commit();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_lq:
                this.mLqTv.setTextColor(getActivity().getResources().getColor(R.color.red));
                this.mZqTv.setTextColor(getActivity().getResources().getColor(R.color.common_60));
                this.mLqV.setBackgroundColor(getActivity().getResources().getColor(R.color.red));
                this.mZqV.setBackgroundColor(getActivity().getResources().getColor(R.color.circle_remark_publish_bg));
                if (this.mJclqFragment.isAdded()) {
                    getActivity().getSupportFragmentManager().beginTransaction().hide(this.mJczqFragment).show(this.mJclqFragment).commit();
                    return;
                } else {
                    getActivity().getSupportFragmentManager().beginTransaction().hide(this.mJczqFragment).add((int) R.id.view_container, this.mJclqFragment).commit();
                    return;
                }
            case R.id.rl_zq:
                this.mZqTv.setTextColor(getActivity().getResources().getColor(R.color.red));
                this.mLqTv.setTextColor(getActivity().getResources().getColor(R.color.common_60));
                this.mZqV.setBackgroundColor(getActivity().getResources().getColor(R.color.red));
                this.mLqV.setBackgroundColor(getActivity().getResources().getColor(R.color.circle_remark_publish_bg));
                if (this.mJczqFragment.isAdded()) {
                    getActivity().getSupportFragmentManager().beginTransaction().hide(this.mJclqFragment).show(this.mJczqFragment).commit();
                    return;
                } else {
                    getActivity().getSupportFragmentManager().beginTransaction().add((int) R.id.view_container, this.mJczqFragment).commit();
                    return;
                }
            default:
                return;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}